<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Msgonline extends MY_Controller {
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		
		$this->tab = 'platform';
	}
	
	function zhs_letter(){		
		$this->load->model('Message_model', 'message');
		
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		
		$vdata = $this->message->get_message_backup_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/msgonline/zhs_letter/?';
		$config['total_rows'] = $vdata['message_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$this->load->model('Systemtemplet_model');
		
		//站内信模板
		$vdata['msgtemplets'] = $this->Systemtemplet_model->get_templet_list(3);
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'zhs_linkslist';
		$this->load->view('/sys_admin/site/msgonline_letter', $vdata);
	}
	
	function add_zhs_letter_view(){
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'zhs_linkslist';
		
		$this->load->model('Systemtemplet_model');
		
		//站内信模板
		$vdata['msgtemplets'] = $this->Systemtemplet_model->get_templet_list(3);
		
		$this->load->view('/sys_admin/site/msgonline_letter_add', $vdata);
	}
	
	function zhs_linkslist(){
		$data = array(
				'title'=>$this->input->post('title'),
				'content'=>trim($this->input->post('content')),
				'templet_id'=>intval($this->input->post('templet_id')),
				'collectname'=>trim($this->input->post('collectname')),
		
			);
		  		
		if($data['templet_id'] == ''){
			$ret['msg'] = '模板不能为空';
		}else if($data['collectname'] == ''){
			$ret['msg'] = '收件人不能为空';
		}else if($data['title'] == ''){
			$ret['msg'] = '标题不能为空';
		}elseif($data['content'] == ''){
			$ret['msg'] = '内容不能为空';	
		}
		
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
		
		
		$uid = $data['collectname'];
		$uid_arr = explode(',', $uid);
		foreach ($uid_arr as $v){
			//发送站内信
			if($data['templet_id'] > 0){
				$msgdata['user_id'] = $v;
				$msgdata['content'] = $data['content'];
				$msgdata['title'] = $data['title'];
				$msgdata['templet'] = $data['templet_id'];
				$res = $this->send_msg($msgdata);
				if($res < 1){ $ret['msginfo']="3";}
			}
		}
		
		
		$this->load->model('Message_model', 'message');
		
		$bdata['sent_user'] = $this->input->post('sendname');
		$bdata['receive_user'] = $this->input->post('collectnamestr');
		$bdata['message_type'] = $data['templet_id'];
		$bdata['title'] = $data['title'];
		$bdata['content'] = $data['content'];
		
		if($ret['msginfo']>0){
			$ret['msg'] = 'error';
		}else{
			$bdata['fstatus'] = 1;
			$ret['msg'] = 'succ';
		}	
		
		$this->message->add_message_backup($bdata);
		echo json_encode($ret);
	   	exit;
	}
	
	private function post_data(){		
		$data = array(
				'title'=>$this->input->post('title'),
				'content'=>trim($this->input->post('content')),
				'application_scene'=>trim($this->input->post('application_scene')),
			);
		  		
		if($data['title'] == ''){
			$ret['msg'] = '标题不能为空';
		}elseif($data['application_scene'] == ''){
			$ret['msg'] = '应用场景不能为空';
		}elseif($data['content'] == ''){
			$ret['msg'] = '内容不能为空';	
		}
		
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
		
  		return $data;
	}
	
	
	private function msgonline_arrays($type){
		$this->load->model('Systemtemplet_model');
		
		$vdata['type'] = $type;
		$vdata['temp'] = $this->Systemtemplet_model->arrays('sys_templet_type');
		$vdata['tab'] = $this->tab;
		$subs = $this->Systemtemplet_model->arrays('sys_templet_sub');
		$vdata['sub'] = $subs[$type];
		return $vdata;
	}
	
	function add_view($type){
		
		$vdata = $this->msgonline_arrays($type);
		
		$this->load->view('/sys_admin/site/msgonline_add', $vdata);
	}
	
	function add(){
		$data = $this->post_data();
		$data['add_time'] = time();
		$data['type'] = intval($this->input->post('type'));
		
		$this->load->model('Systemtemplet_model');
  		$id = $this->Systemtemplet_model->add($data);
  		
		$this->load->model('log_model');
		$temp = array(1=>'邮件模板',2=>'短信模板',3=>'站内信模板');
		
		$this->log_model->add_log('[添加]['.$temp[$data['type']].']['.$this->input->post('title').']');
		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	private function msgonline_obj($id){
		$this->load->model('Systemtemplet_model');
		$msg = $this->Systemtemplet_model->get_templet_obj($id);
		return $msg;
	}
	
	
	function edit_view($id){
		
		$msg = $this->msgonline_obj($id);
		$vdata = $this->msgonline_arrays($msg['type']);		
		$vdata['msgonline'] = $msg;		
		
		$this->load->view('/sys_admin/site/msgonline_edit', $vdata);
	}
	
	function view(){
		$id = $this->input->post('id');
		
		$msg = $this->msgonline_obj($id);
		
		$response_html ="";
		if($msg){
			$msgonline['msgonline'] = $msg;
			$response_html = $this->load->view('sys_admin/site/msgonline_view',$msgonline,true);
		}
						
		echo $response_html;
		exit;
		
	}
	
	
	
	function edit(){
		$id 		= $this->input->post('id');
		$data = $this->post_data();
		
		$this->load->model('Systemtemplet_model');
  		$this->Systemtemplet_model->update($id, $data);
  		
		$this->load->model('log_model');$this->log_model->add_log('[修改][系统模板]'.'ID=='.$id );
   		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	public function index(){		
		$this->load->model('Systemtemplet_model');
		
		$type = $this->input->get('type');
		
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$title 				= $this->input->get('title');
		
		$data = array();
		if($title != ''){
			$data['where']['title'] = $title;
		}
		
		if($type != 0){
			$data['where']['type'] = $type;
		}
		
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		$data['select'] 	= 1;
		$this->load->model('Systemtemplet_model');
		
		$vdata = $this->msgonline_arrays($type);
		
		$list = $this->Systemtemplet_model->templet_list($data);
		$vdata['templet_list'] = $list['templet_list'];
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/msgonline/index/?type='.$type;
		$config['total_rows'] = $vdata['templet_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
				
		$this->load->view('/sys_admin/site/msgonline', $vdata);
	}
	
	
	function msgstop(){
		$id 				= $this->input->post('id');
  		$data["is_stop"]		= 1;
  		$this->load->model('Systemtemplet_model');
		echo  $this->Systemtemplet_model->update($id, $data);
  		$this->load->model('log_model');
  		$this->log_model->add_log('[暂停][模板]');
	}
	

=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Msgonline extends MY_Controller {
    
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		
		$this->tab = 'platform';
	}
	
	function zhs_letter(){		
		$this->load->model('Message_model', 'message');
		
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		
		$vdata = $this->message->get_message_backup_list($data);
		
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/msgonline/zhs_letter/?';
		$config['total_rows'] = $vdata['message_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$this->load->model('Systemtemplet_model');
		
		//站内信模板
		$vdata['msgtemplets'] = $this->Systemtemplet_model->get_templet_list(3);
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'zhs_linkslist';
		$this->load->view('/sys_admin/site/msgonline_letter', $vdata);
	}
	
	function add_zhs_letter_view(){
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'zhs_linkslist';
		
		$this->load->model('Systemtemplet_model');
		
		//站内信模板
		$vdata['msgtemplets'] = $this->Systemtemplet_model->get_templet_list(3);
		
		$this->load->view('/sys_admin/site/msgonline_letter_add', $vdata);
	}
	
	function zhs_linkslist(){
		$data = array(
				'title'=>$this->input->post('title'),
				'content'=>trim($this->input->post('content')),
				'templet_id'=>intval($this->input->post('templet_id')),
				'collectname'=>trim($this->input->post('collectname')),
		
			);
		  		
		if($data['templet_id'] == ''){
			$ret['msg'] = '模板不能为空';
		}else if($data['collectname'] == ''){
			$ret['msg'] = '收件人不能为空';
		}else if($data['title'] == ''){
			$ret['msg'] = '标题不能为空';
		}elseif($data['content'] == ''){
			$ret['msg'] = '内容不能为空';	
		}
		
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
		
		
		$uid = $data['collectname'];
		$uid_arr = explode(',', $uid);
		foreach ($uid_arr as $v){
			//发送站内信
			if($data['templet_id'] > 0){
				$msgdata['user_id'] = $v;
				$msgdata['content'] = $data['content'];
				$msgdata['title'] = $data['title'];
				$msgdata['templet'] = $data['templet_id'];
				$res = $this->send_msg($msgdata);
				if($res < 1){ $ret['msginfo']="3";}
			}
		}
		
		
		$this->load->model('Message_model', 'message');
		
		$bdata['sent_user'] = $this->input->post('sendname');
		$bdata['receive_user'] = $this->input->post('collectnamestr');
		$bdata['message_type'] = $data['templet_id'];
		$bdata['title'] = $data['title'];
		$bdata['content'] = $data['content'];
		
		if($ret['msginfo']>0){
			$ret['msg'] = 'error';
		}else{
			$bdata['fstatus'] = 1;
			$ret['msg'] = 'succ';
		}	
		
		$this->message->add_message_backup($bdata);
		echo json_encode($ret);
	   	exit;
	}
	
	private function post_data(){		
		$data = array(
				'title'=>$this->input->post('title'),
				'content'=>trim($this->input->post('content')),
				'application_scene'=>trim($this->input->post('application_scene')),
			);
		  		
		if($data['title'] == ''){
			$ret['msg'] = '标题不能为空';
		}elseif($data['application_scene'] == ''){
			$ret['msg'] = '应用场景不能为空';
		}elseif($data['content'] == ''){
			$ret['msg'] = '内容不能为空';	
		}
		
		if($ret['msg']){
			echo json_encode($ret);exit;
		}
		
  		return $data;
	}
	
	
	private function msgonline_arrays($type){
		$this->load->model('Systemtemplet_model');
		
		$vdata['type'] = $type;
		$vdata['temp'] = $this->Systemtemplet_model->arrays('sys_templet_type');
		$vdata['tab'] = $this->tab;
		$subs = $this->Systemtemplet_model->arrays('sys_templet_sub');
		$vdata['sub'] = $subs[$type];
		return $vdata;
	}
	
	function add_view($type){
		
		$vdata = $this->msgonline_arrays($type);
		
		$this->load->view('/sys_admin/site/msgonline_add', $vdata);
	}
	
	function add(){
		$data = $this->post_data();
		$data['add_time'] = time();
		$data['type'] = intval($this->input->post('type'));
		
		$this->load->model('Systemtemplet_model');
  		$id = $this->Systemtemplet_model->add($data);
  		
		$this->load->model('log_model');
		$temp = array(1=>'邮件模板',2=>'短信模板',3=>'站内信模板');
		
		$this->log_model->add_log('[添加]['.$temp[$data['type']].']['.$this->input->post('title').']');
		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	private function msgonline_obj($id){
		$this->load->model('Systemtemplet_model');
		$msg = $this->Systemtemplet_model->get_templet_obj($id);
		return $msg;
	}
	
	
	function edit_view($id){
		
		$msg = $this->msgonline_obj($id);
		$vdata = $this->msgonline_arrays($msg['type']);		
		$vdata['msgonline'] = $msg;		
		
		$this->load->view('/sys_admin/site/msgonline_edit', $vdata);
	}
	
	function view(){
		$id = $this->input->post('id');
		
		$msg = $this->msgonline_obj($id);
		
		$response_html ="";
		if($msg){
			$msgonline['msgonline'] = $msg;
			$response_html = $this->load->view('sys_admin/site/msgonline_view',$msgonline,true);
		}
						
		echo $response_html;
		exit;
		
	}
	
	
	
	function edit(){
		$id 		= $this->input->post('id');
		$data = $this->post_data();
		
		$this->load->model('Systemtemplet_model');
  		$this->Systemtemplet_model->update($id, $data);
  		
		$this->load->model('log_model');$this->log_model->add_log('[修改][系统模板]'.'ID=='.$id );
   		$ret['msg'] = 1;
		echo json_encode($ret);
   		exit;
	}
	
	public function index(){		
		$this->load->model('Systemtemplet_model');
		
		$type = $this->input->get('type');
		
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$title 				= $this->input->get('title');
		
		$data = array();
		if($title != ''){
			$data['where']['title'] = $title;
		}
		
		if($type != 0){
			$data['where']['type'] = $type;
		}
		
		$data['page_size']  = sys_admin_LIST_PAGE_SIZE;
		$data['page_start'] = (int)$per_page;
		$data['select'] 	= 1;
		$this->load->model('Systemtemplet_model');
		
		$vdata = $this->msgonline_arrays($type);
		
		$list = $this->Systemtemplet_model->templet_list($data);
		$vdata['templet_list'] = $list['templet_list'];
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/msgonline/index/?type='.$type;
		$config['total_rows'] = $vdata['templet_count'];
		$config['per_page'] = sys_admin_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
				
		$this->load->view('/sys_admin/site/msgonline', $vdata);
	}
	
	
	function msgstop(){
		$id 				= $this->input->post('id');
  		$data["is_stop"]		= 1;
  		$this->load->model('Systemtemplet_model');
		echo  $this->Systemtemplet_model->update($id, $data);
  		$this->load->model('log_model');
  		$this->log_model->add_log('[暂停][模板]');
	}
	

>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}